<template>
	<view class="order">
		<view class="order-input">
			<uni-search-bar placeholder="根据关键字搜索订单" clearButton="always
			" :showSync='true' @serValue="serValue" :show='true'></uni-search-bar>
		</view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption" height="0" style="min-height: 0;">
			<view class="item-content">

				<view class="item" v-for="(item,index) in  datalist" @click="orderDetail(item)" :key='index'>
					<view class="buyers">
						<view class="buyers-bigBox">
							<view class="buyers-box">
								<view class="buyers-left">
									<!-- 购买人姓名 -->
									<text class="buyers-name">{{item.name}}</text>
									<view class="courier" v-if="item.self ==10">
										快递订单
									</view>
									<view class="courier" v-if="item.self ==20">
										自提订单
									</view>
								</view>
								<!-- 订单状态 -->
								<view class="buyers-right">
									<text class="buyers-mobile">{{item.phone}}</text>
									<text class="goods-status">{{ item.orderStatusText }} </text>
								</view>
							</view>
							<view class="goods-detail">
								<view class="goods" v-for="(item1,index1) in item.productList" :key="index1">
									<!-- 新增加的模块提示 -->
									<view class="goods-newly">
										<view>
											<view class="goods-newly_icon" style="margin: 5px 0px;">
												{{ item.orderSourceText }}
											</view>
										</view>
										<view>
											<view v-if="item.status==50" class="goods-sta sta1">待自提</view>
											<view v-if="item.status==40" class="goods-sta sta1">待发货</view>
										</view>
									</view>
									<view class="goods-top">
										<view class="goods-img">
											<image :src="item1.imagePath" mode=""></image>
										</view>
										<view class="goods-detail-text">
											<view class="goods">
												<span
													style='text-overflow: ellipsis;overflow: hidden;white-space: nowrap;'>
													{{item1.productName}}</span>
												<span>¥{{item1.productPrice}}</span>
											</view>
											<view class="goods-species">
												<span>{{item1.productAttr}}</span>
												<span>x{{item1.totalNum}}</span>
											</view>

										</view>
									</view>

									<!-- 	
								手动注释
								 <view class="packing">
										<view class="packing_right" v-if="item1.group_type!=2">
											<text>定金¥{{item1.earnest}}，</text>
											<text v-if="item1.final_payment>0">尾款¥{{item1.final_payment}}，</text>
											<text>总价¥{{Math.round((Number(item1.earnest)+Number(item1.final_payment))*1000)/1000}}</text>
										</view>
										<span
											v-if="item1.group_type==2">总价¥{{Math.round((Number(item1.earnest)+Number(item1.final_payment))*1000)/1000}}</span>
									</view> -->

									<!-- 自提  自提订单20且订单状态为待确认20-->
									<view class="time1" @click.stop="time(item1,item)"
										v-if="item.self ===20 && item.status === 20">
										{{ (item1.expectDeliveryTime === '' || item1.expectDeliveryTime === null ) 
										? '请选择自提时间': formaterTime(item1.expectDeliveryTime)}}
									</view>

									<!-- 确认后显示快递的时间 -->
									<view class="time1" v-if="item.self ===10 && item.status === 20"
										@click.stop="time(item1,item)">
										{{ (item1.expectDeliveryTime === '' || item1.expectDeliveryTime === null )
											? '请选择发货时间': formaterTime(item1.expectDeliveryTime)}}
									</view>
									<view class="time1"
										v-if="item.self==20 && item.status!=20 && item1.expectDeliveryTime ">
										确定在{{ formaterTime(item1.expectDeliveryTime) }}可自提
									</view>
									<view class="time1"
										v-if="item.self==10 && item.status!=20 && item1.expectDeliveryTime">
										确定在{{ formaterTime(item1.expectDeliveryTime) }}可发货
									</view>

									<!-- 	
								手动注释
								<view class="time1" v-if="item.self==1 && item.status==2&&(item1.group_type==0 
									||item1.group_type==4 || item1.group_type==5)"
										@click.stop="time(item1,item)">
										{{item1.time==''?'请选择发货时间':item1.time}}
									</view> -->


									<!-- 时间 -->
									<!-- 
									手动注释
									<view class="time1"
										v-if="item.self==0 && item.status!=2 && item.status!=10&&item1.group_type!=3 ">
										确定在{{formDate(item1.date)}}可自提
									</view>
									<view class="time1"
										v-if="item.self==1 && item.status!=2 && item.status!=10&&item1.group_type!=3">
										确定在{{formDate(item1.date)}}可发货
									</view> -->
									<!-- 时间 -->
									<!-- 1130 -->
									<!-- 	
								手动注释
								<view class="time1"
										v-if="item.self==0 && item.status==2&&item1.group_type!=0&&item1.group_type!=3 && item1.group_type!=4 && item1.group_type!=5">
										确定在{{formDate(item1.date)}}可自提
									</view>
									<view class="time1"
										v-if="item.self==1 && item.status==2&&item1.group_type!=0&&item1.group_type!=3 && item1.group_type!=4 && item1.group_type!=5">
										确定在{{formDate(item1.date)}}可发货
									</view>
									<view class="time1" v-if="item.status==10">
										{{timeShow(item1.expected_time,item1.spec,item.self,item1.stock,item1.amount,item1)}}
									</view> -->
									<!-- 选择生成部门 -->
									<!-- <view class="time1" v-if="item.status==3">
										
									</view> -->
									<view class="time1">
										{{item1.productAddress}}
									</view>

									<!-- 
									手动注释
									<view v-if="item.status==4">
										<view >
											<view class=" sta" :class="[item1.residue_status=='该商品已全部自提'?'goods-sta2 sta3':(item1.residue_status=='该商品未自提'?'goods-sta sta1':'goods-sta1 sta2')]" >{{item1.residue_status}}</view>
										</view>
									</view>
									<view v-if="item.status==5">
										<view >
											<view class=" sta" :class="[item1.residue_status=='该商品已全部发货'?'goods-sta2 sta3':(item1.residue_status=='该商品未发货'?'goods-sta sta1':'goods-sta1 sta2')]" >{{item1.residue_status}}</view>
										</view>
									</view> -->
								</view>


								<view class="total-price">
									<span>商品总计：</span>
									<view class='total'>
										{{Number(item.coupons_money)!=0?`优惠￥${item.coupons_money}，`:''}}
										<text
											v-if="Math.round((Number(item.final_payment)-Number(item.coupons_money))*1000)/1000<0">总价¥{{item.earnest}}，</text>
										<text v-else>定金¥{{item.earnest}}，</text>
										<text
											v-if="Math.round((Number(item.final_payment)-Number(item.coupons_money))*1000)/1000>0">尾款¥{{Math.round((Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}，</text>
										<text>实付金额¥{{Math.round((Number(item.earnest)+Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}</text>
									</view>
									<span v-if="item.orderStatus==2"
										class='total'>{{Number(item.coupons_money)!=0?`优惠￥${item.coupons_money}，`:''}}实付金额¥{{Math.round((Number(item.earnest)+Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}</span>
								</view>

								<!--
								  手动注释/提取else部分
								 <view v-if="isFarmGoodOrder(item)" class="total-price">
									<span>商品总计：</span>
									<span v-if="item.orderStatus!=2"
										class='total'>{{Number(item.coupons_money)!=0?`优惠￥${item.coupons_money}，`:''}}
										实付金额¥{{Math.round((Number(item.earnest)+Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}</span>
									<span v-if="item.orderStatus==2"
										class='total'>{{Number(item.coupons_money)!=0?`优惠￥${item.coupons_money}，`:''}}
										实付金额¥{{Math.round((Number(item.earnest)+Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}</span>
								</view>
								<view v-else class="total-price">
									<span>商品总计：</span>
									<view v-if="item.orderStatus!=2"
										class='total'>{{Number(item.coupons_money)!=0?`优惠￥${item.coupons_money}，`:''}}
										<text v-if="Math.round((Number(item.final_payment)-Number(item.coupons_money))*1000)/1000<0">总价¥{{item.earnest}}，</text>
										<text v-else>定金¥{{item.earnest}}，</text>
										<text v-if="Math.round((Number(item.final_payment)-Number(item.coupons_money))*1000)/1000>0">尾款¥{{Math.round((Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}，</text>
										<text>实付金额¥{{Math.round((Number(item.earnest)+Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}</text>
										</view>
									<span v-if="item.orderStatus==2"
										class='total'>{{Number(item.coupons_money)!=0?`优惠￥${item.coupons_money}，`:''}}实付金额¥{{Math.round((Number(item.earnest)+Number(item.final_payment)-Number(item.coupons_money))*1000)/1000}}</span>
								</view> -->
							</view>
							<view class="order-number">
								<span>订单编号：</span>
								<span class='number'>{{item.orderNo}}</span>
							</view>
							<view class="order-number">
								<span>下单时间：</span>
								<span class='number'>{{item.createTime}}</span>
							</view>
							<view class="order-time">
								<span>用友单据编号：</span>
								<span class='time'>{{!item.yonyouCode?'单据未同步':item.yonyouCode}}</span>
							</view>
							<view class="order-btn">
								<view class="common btns" v-if="item.status === 20">
									<view @click.stop="confirmOrder(item)">
										确认订单
									</view>
								</view>
								<view class="" v-if="item.status==3 ||item.status==4||item.status==5">
									<!-- <view class="refund-btn btn" @click.stop="refund(item)">退款</view> -->
								</view>
								<!-- 待付尾款 -->
								<view class="confirm-btn btn btns" v-if="item.status==30"
									@click.stop="confirmPayment(item)">
									确认尾款</view>


								<!-- 	
							  手动注释
							<view class="confirm-btn btn" v-if="item.status==5 || item.status==4 "
									:class="[item.Eve=='已全部发货'||item.Eve=='已全部自提'?'quanbu':'confirm-btn btn']"
									@click.stop="reissue(item)">{{item.Eve}}</view>
								<view class="confirm-btn btn" v-if="item.status==4 && item.amountshow">已全部发货</view>
								<view class="confirm-btn btn" v-if="item.status==8" @click.stop="checkEvaluation(item)">
									查看评价</view>
								<view class="common" v-if="item.status==10 && item.is_back!=3 && item.is_back!=2">
									<view class="refund-btn btn" @click.stop="reject(item)">拒绝</view>
									<view class="confirm-btn btn" @click.stop="aggree(item)">同意</view>
								</view> -->
							</view>
						</view>
					</view>
				</view>

			</view>
		</mescroll-body>
		<!-- <view class="pop-up"  v-if="calendar" @click="close" ></view>
		<view class="content-pop"v-if="calendar" >
			<view class="top"  >
				<text  @click="cancel">取消</text>
				<text class="confirm" @click="confirm">确认</text>
			</view>
			<view class="calendar" >
				<uni-calendar    :start-date="'2019-3-2'" :end-date="'2019-5-20'" @change="calendarChange">
				</uni-calendar>
			</view> -->
		<uni-calendar ref="calendar" class="uni-calendar--hook" :selected="info.selected" :date="info.data"
			:insert="info.insert" :lunar="info.lunar" :startDate="info.startDate" :range="info.range" @confirm="confirm"
			@close="close" />
		<!-- </view> -->

		<!-- <view class="picker" v-if="isShow"> -->
		<!-- <picker class="picker" @change="bindPickerChange" :value="index" :range="array"  v-if="isShow" >
			</picker> -->
		<w-picker :visible.sync="visible" mode="selector" value="1" default-type="label" :default-props="defaultProps"
			:options="selectorList" @confirm="onConfirm($event,'selector')" @cancel="onCancel" ref="selector">
		</w-picker>
		<!-- </view> -->
	</view>

</template>
<script>
	import uniCalendar from '@/components/uni-calendar/uni-calendar.vue'
	import wPicker from "@/components/w-picker/w-picker.vue";
	// 添加下拉刷新组件
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		components: {
			uniCalendar,
			wPicker
		},
		data() {
			return {
				tab: [{
						name: '全部',
						value: 0,
						filter: 'all'
					},
					{
						name: '待支付',
						value: 1,
						filter: 'payment'
					},
					{
						name: '待确认',
						value: 2,
						filter: 'notConfirm'
					},
					{
						name: '待付尾款',
						value: 3,
						filter: 'notFinalPayment'
					},
					{
						name: '待发货',
						value: 5,
						filter: 'delivery'
					},
					{
						name: '待自提',
						value: 4,
						filter: 'notPickup'
					},

					{
						name: '待收货',
						value: 6,
						filter: 'received'
					},
					{
						name: '待评价',
						value: 7,
						filter: 'notComment'
					},
					{
						name: '已评价',
						value: 8,
						filter: 'commented'
					},
					{
						name: '退款',
						value: 10,
						filter: 'refund'
					},
					{
						name: '已取消',
						value: 11,
						filter: 'cancel'
					}
				],
				datalist: [],
				datalist1: [],
				curren: 0,
				goodsList: [],
				title: 'picker',
				selectorList: [],
				defaultProps: {
					"label": "title"
				},
				index: 0,
				calendar: false,
				isShow: false,
				visible: false,
				length: 0,
				date: '',
				id: 0,
				// 下拉刷新的组件 参数 可以 改变的
				downOption: {
					use: false,
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					auto: false, // 不自动加载
					noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '~ 空空如也 ~', // 提示
						icon: '/static/home/saber.png'
					},
					textNoMore: '—— 没有更多了 ——'
				},
				order_goods: [],
				info: {
					lunar: true,
					range: false,
					insert: false,
					selected: [],
					data: '',
					startDate: ''
				},

				department: '',
				indexd: 0,
				indexc: 0,
				pitchItem: '', //选中的item
				isNoEX: true,
				pickItem: {},
				searchMobile:''
			}
		},
		onLoad(options) {

			uni.$on('updateOrderList', (data) => {
				this.orderListAll(this.tab[this.curren].filter)
			})
			uni.$on('detailStatus', () => {
				this.orderListAll(this.status)
			})
			if (options.status) {
				this.curren = Number(options.status) - 1
				this.orderListAll(options.status)

			} else {
				this.orderListAll('')

			}
			//this.productionDepartment()
		},
		methods: {
			serValue(data) {
				this.searchMobile =data 
				this.mescroll.resetUpScroll()
			},
			formaterTime(time) {
				if (time) {
					const date = new Date(time)
					const year = date.getFullYear()
					const month = date.getMonth() + 1
					const day = date.getDate()
					return `${year}-${month >=10? month :'0'+month }-${day>=10? day :'0'+day}`
				}
				return ''
			},
			onTest() {
				window.open('#小程序://上云丰/vmIQrRgFtQks5Fv')
			},
			orderDetail(item) {
				uni.navigateTo({
					url: '/pages/orderList/orderListDetail/orderListDetail?orderId=' + item.orderId
				})
			},
			price(item1, item) {
				console.log(item1);
				console.log(item);
				// item.order_goods.forEach(citem=>{
				// 	citem
				// })
				if (item1.group_type == 0) {
					if (item1.classifyname != '种苗') {
						if (item.all_amount < 100000) {
							if (item1.amount < 10000) {
								item1['price_money'] = item1.retail_price
							} else if (item1.amount < 100000) {
								item1['price_money'] = item1.price_one
							} else {
								item1['price_money'] = item1.price_two
							}
						} else {
							item1['price_money'] = item1.price_two
						}
					} else {
						if (item.all_amount < 100000) {
							if (item1.amount < 10000) {
								item1['price_money'] = item1.zhongmiao_price
							} else if (item1.amount < 100000) {
								item1['price_money'] = item1.zhongmiao_price_one
							} else {
								item1['price_money'] = item1.zhongmiao_price_two
							}
						} else {
							item1['price_money'] = item1.zhongmiao_price_two
						}
					}
				} else {
					item1['price_money'] = item1.retail_price
				}
				console.log(item1.price_money);
				return item1.price_money
			},
			product(item1, item) {
				if (item1.group_type == 0) {
					if (item.status == 2) {
						this.pitchItem = item1
						this.$refs.selector.show()
					}
				}
			},
			toNewOrderJson(order) {
				const json = {
					orderId: order.orderId,
					name: order.extractName, //提货人
					self: order.deliveryType, //10 快递 20 自提
					phone: order.extractPhone, //电话
					orderStatusText: order.orderStatusText,
					productList: order.productList, //订单商品 
					yonyouCode: order.yonyouCode,
					createTime: order.createTime,
					orderNo: order.orderNo,
					orderSourceText: order.orderSourceText,
					orderSource: order.orderSource,
					status: order.status
				}
				return json
			},
			time(item1, item) {
				console.log('item1', item1)
				console.log('item', item)

				this.pickItem = {
					order: item,
					product: item1
				}
				setTimeout(() => {
					this.$refs.calendar.open()
				}, 200)

			},
			// 订单全部列表
			orderListAll(mobile, pageNumber = 1) {
				const $this = this
				this.status = status
				this.api.orderListAll({
					dataType: 'all',
					pageIndex: pageNumber,
					pageSize: 5,
					mobile:mobile
				}).then(res => {
					console.log('订单数据', res)
					console.log(res)
					const data = res.data.data.orderList.records
					const code = res.data.code
					let arrys = $this.datalist
					if (pageNumber === 1)
						arrys = []
					if (code === 1 &&
						data && data.length > 0) {
						data.forEach(order => {
							const json = $this.toNewOrderJson(order)
							arrys.push(json)
						})
					}
					this.datalist = arrys
					// this.datalist = res.data.data.order.filter(item => {
					// 	if (item.order_goods.length > 0) {
					// 		// 判断是不是秒杀 1是拼团 2是秒杀
					// 		if (item.order_goods[0].group_type == 1) {
					// 			item['orderStatus'] = 1
					// 		} else if (item.order_goods[0].group_type == 2) {
					// 			item['orderStatus'] = 2
					// 		} else {
					// 			item['orderStatus'] = 0
					// 		}
					// 		item['is_success'] = item.order_goods[0].is_success
					// 		// 4是自提
					// 		if (item.self == 0) {
					// 			item.order_goods.map(citem => {
					// 				let cnbs = citem.spec.split(',')[0]
					// 				citem['classifyname'] = cnbs
					// 				citem['time'] = ''
					// 				// citem['department']=''
					// 				console.log(citem);
					// 				// 如果相等的话 说明没有发货
					// 				if (Number(citem.residue_amount) == Number(citem.amount)) {
					// 					console.log(12345);
					// 					citem['residue_status'] = '该商品未自提'
					// 					// 如果等于0的话 说明改商品已经全部发货
					// 				} else if (Number(citem.residue_amount) != 0) {
					// 					console.log(112);
					// 					citem['residue_status'] =
					// 						`该商品剩余${Number(citem.residue_amount)}件未自提`
					// 					// 如果不等于0 两个也不相等 说明 是已经发货 但是没有全部发货
					// 				} else {
					// 					citem['residue_status'] = '该商品已全部自提'
					// 				}
					// 			})
					// 			let cn = item.order_goods.filter(itemc => {
					// 				// 如果相等 则返回一个item
					// 				return itemc.residue_status != '该商品未自提'
					// 			})
					// 			let cns = item.order_goods.filter(itemc => {
					// 				return itemc.residue_status != '该商品已全部自提'
					// 			})
					// 			// 如果cns 为0的话 说明已经全部自提
					// 			if (cns.length == 0) {
					// 				item['Eve'] = '已全部自提'
					// 			} else if (cn.length == 0) {
					// 				item['Eve'] = '确认自提'
					// 			} else {
					// 				item['Eve'] = '补发'
					// 			}
					// 			// 5是发货
					// 		} else if (item.self == 1) {
					// 			item.order_goods.map(citem => {
					// 				let cnbs = citem.spec.split(',')[0]
					// 				citem['classifyname'] = cnbs
					// 				citem['time'] = ''
					// 				// citem['department']=''
					// 				// 如果相等的话 说明没有发货
					// 				if (Number(citem.residue_amount) == Number(citem.amount)) {
					// 					console.log(12345);
					// 					citem['residue_status'] = '该商品未发货'
					// 					// 如果等于0的话 说明改商品已经全部发货
					// 				} else if (Number(citem.residue_amount) != 0) {
					// 					console.log(112);
					// 					citem['residue_status'] =
					// 						`该商品剩余${Number(citem.residue_amount)}件未发货`
					// 					// 如果不等于0 两个也不相等 说明 是已经发货 但是没有全部发货
					// 				} else {
					// 					citem['residue_status'] = '该商品已全部发货'
					// 				}
					// 			})
					// 			let cn = item.order_goods.filter(itemc => {
					// 				// 如果相等 则返回一个item
					// 				return itemc.residue_status != '该商品未发货'
					// 			})
					// 			let cns = item.order_goods.filter(itemc => {
					// 				return itemc.residue_status != '该商品已全部发货'
					// 			})
					// 			console.log(cn);
					// 			console.log(cns);
					// 			// 如果cns 为0的话 说明已经全部发货
					// 			if (cns.length == 0) {
					// 				console.log(112);
					// 				item['Eve'] = '已全部发货'
					// 			} else if (cn.length == 0) {
					// 				console.log(12345);
					// 				item['Eve'] = '确认发货'
					// 			} else {
					// 				console.log(12445);
					// 				item['Eve'] = '补发'
					// 			}
					// 		}

					// 	}
					// 	return item.order_goods.length > 0
					// })

				}).catch(err => {

				})
			},
			// 获取传入下单时间跟天数
			pickTime(create, time) {
				let cn = Number(time)
				let cs = cn * 1000 * 60 * 60 * 24
				let ctime = new Date(cs + Number(create) * 1000)
				let y = ctime.getFullYear()
				let m = ctime.getMonth() + 1
				let d = ctime.getDate()
				let csv = y + '-' + m + '-' + d
				return csv
			},
			// 生产部门
			productionDepartment() {
				this.api.productionDepartment()
					.then(res => {
						console.log(res.data.data);
						this.selectorList = res.data.data
						console.log(this.selectorList);
					})
					.catch(err => {
						this.tui.toast(err)
					})
			},
			// 搜索
			search() {
				uni.navigateTo({
					url: '/pages/search/searchs'
				})
			},
			// 获取现在的时间戳
			nowTime() {
				let times = new Date()
				console.log(times);
				let year = times.getFullYear()
				let m = times.getMonth() + 1
				let d = times.getDate()
				let csv = year + '-' + m + '-' + d
				return csv
			},
			// confirm(e) {
			// 	console.log('confirm 返回:', e)
			// },
			close() {
				console.log('弹窗关闭');
			},
			// 分割字符串
			Unsplit(goods_spec) {
				var spec = goods_spec.split(',')
				return spec[0] + ';' + '; ' + spec[0]
			},
			// 日历取消
			cancel() {
				// this.calendar = false
			},
			// 日历确认
			confirm(e) {
				const $this = this
				const selectItem = $this.pickItem
				$this.datalist.map(item => {
					if (item.orderId === selectItem.order.orderId) {
						if (item.productList && item.productList.length > 0) {
							item.productList.forEach((prod, index) => {
								$this.$set(prod, 'expectDeliveryTime', e.fulldate)
							})
						}
					}

				})
			},
			// picker确认
			onConfirm(e) {
				this.pitchItem.department = e.obj.title
			},
			// picker取消
			onCancel() {
				console.log(34)
			},
			// 顶部导航
			changetab(index, status) {

				// this.datalist = this.datalist1
				this.curren = index
				if (index != 0) {
					this.datalist = this.datalist.filter(item => item.status == status)
				}
				if (status != 1) {
					// this.orderListAll(status)
					this.status = status
					this.mescroll.resetUpScroll()
				} else {
					this.status = 0
					this.mescroll.resetUpScroll()
				}


			},
			orderStatus(status) {
				this.api.orderListPart({
					status: status,
					uid: uni.getStorageSync('uid')
				}).then(res => {
					console.log(res.data)
					this.datalist = res.data.data.order
					// this.datalist1 = res.data.data.order


				}).catch(err => {

				})
			},
			aggree(item) {
				var that = this
				uni.showModal({
					title: '确定同意该退款？',
					content: '同意后无法取消',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							that.payRefund(item.id, item.out_trade_no)
							that.mescroll.resetUpScroll()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			reject(item) {
				var that = this
				uni.showModal({
					title: '确定拒绝该退款？',
					content: '拒绝后无法取消',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							that.refuseRefund(0, item.id)

						} else if (res.cancel) {
							console.log('用户点击取消');

						}
					}
				});
			},
			// 退款
			refund(item) {
				var that = this
				uni.showModal({
					title: '确认取消这笔订单？',
					content: '退款将退回给客户，取消后无法撤销',
					success: function(res) {
						if (res.confirm) {
							// console.log('用户点击确定');
							// if(item.status==1||item.status==2||item.status==3){

							// }else{
							// 	console.log(item.id);

							// }
							// 0 是没有付尾款
							if (item.is_final_payment == 0) {
								that.api.payRefund({
										id: item.id,
										uid: uni.getStorageSync('uid')
									})
									.then(res => {
										console.log(res);
										if (res.data.code == 200) {
											that.tui.toast('退款成功')
											that.orderListAll(10)
											that.changetab(8, 10)
										} else {
											that.tui.toast(res.data.data)
										}
									})
									.catch(err => {})
								// 1 是已经付尾款了
							} else {
								that.api.payRefundAll({
										id: item.id,
										uid: uni.getStorageSync('uid')
									})
									.then(res => {
										console.log(res);
										if (res.data.code == 200) {
											that.tui.toast('退款成功')
											that.orderListAll(10)
											that.changetab(8, 10)
										} else {
											that.tui.toast(res.data.data)
										}
									})
									.catch(err => {
										that.tui.toast(err)
									})
							}
						} else if (res.cancel) {

						}
					}
				});
			},
			// 确认退款
			payRefund(id, number) {
				this.api.payRefund({
						id,
						uid: uni.getStorageSync('uid')
					})
					.then(res => {
						// pay_type是0则是余额退款
						if (res.data.code == 200 && res.data.data.pay_type == 0) {
							this.api.refundCallbackOutTradeNo(number)
								.then(res => {
									this.orderListAll(0)
								})
						} else {
							this.orderListAll(0)
						}
					})
					.catch(err => {
						this.tui.toast(err)
					})
			},
			formDate(date) {
				const dt = new Date(date * 1000)
				const y = dt.getFullYear()
				const m = (dt.getMonth() + 1 + '').padStart(2, '0')
				const d = (dt.getDate() + '').padStart(2, '0')
				const hh = (dt.getHours() + '').padStart(2, '0')
				const mm = (dt.getMinutes() + '').padStart(2, '0')
				const ss = (dt.getSeconds() + '').padStart(2, '0')

				return `${y}-${m}-${d} `
			},
			// 取消退款
			refuseRefund(x, id) {
				this.api.refuseRefund({
						id,
						uid: uni.getStorageSync('uid')
					})
					.then(res => {
						if (res.data.code == 500) {
							this.tui.toast(res.data.data)
						} else {
							this.orderListAll(10)
						}
					})
					.catch(err => {
						this.tui.toast(err)
					})
			},
			// 退单接口
			singleCheck(type, order_id) {
				this.api.singleBack({
						type,
						order_id
					})
					.then(res => {
						console.log(res);
					})
					.catch(err => {})
			},
			// 确认支付尾款
			confirmPayment(item) {
				console.log(item);
				var that = this
				uni.showModal({
					title: '确认用户已在线下支付尾款？',
					content: '请仔细核查尾款，提交后不可更改',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							that.api.confirmRefund({
									order_id: item.id
								})
								.then(res => {
									console.log(res);
									that.curren = 3
									that.orderListAll(4)
								})
								.catch(err => {})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 补发
			reissue(item) {
				// uni.navigateTo({
				// 	url: './confirmDelivery/deliveryAllOrPart/deliveryAllOrPart?status='+item.status +'&id='+item.id
				// })
				// if(item.Eve=='确认发货'){

				// }else if(item.Eve=='确认自提'){

				// }else 
				if (item.Eve != '已全部发货' && item.Eve != '已全部自提') {
					if (item.status == 4) {
						uni.navigateTo({
							url: './confirmDelivery/deliveryAllOrPart/deliveryAllOrPart?status=' + item.status +
								'&id=' + item.id + '&order_id=' + item.id
						})
					}
					if (item.status == 5) {
						uni.navigateTo({
							url: './confirmDelivery/deliveryCourier/deliveryCourier?status=' + item.status +
								'&id=' + item.id + '&order_id=' + item.id
						})
					}
				}
			},
			// 确认订单
			confirmOrder(item) {

				const $this = this
				let isTrue = false
				let isBreak = false;
				if (!isTrue) {
					//验证提货时间 
					if (item.productList &&
						item.productList.length > 0) {
						item.productList.forEach(prod => {
							if (!prod.expectDeliveryTime) {
								if (item.self == 10) {
									this.tui.toast(`请选择${prod.productName}发货时间`)
								} else {
									this.tui.toast(`请选择${prod.productName}自提时间`)
								}
								isBreak = true
								return
							}

						})

					}
					if (isBreak)
						return
					const postOrder = {
						orderId: item.orderId,
						pickupTime: $this.formaterTime(item.productList[0].expectDeliveryTime)
					}
					$this.isTrue = true
					$this.api.confirmOrder(postOrder)
						.then(res => {
							$this.isTrue = false
							const {
								code,
								msg
							} = res.data
							if (code === 1) {
								this.tui.toast(msg)
								$this.orderListAll('all', 1)
							} else {
								this.tui.toast(msg)
							}
						})
						.catch(err => {
							$this.tui.toast('订单异常')
							$this.isTrue = false
						})
				} else {
					this.tui.toast('请勿重复提交')
				}

				console.log('确认订单', item);
				// some 返回true时终端遍历
				// every 返回false时终端遍历,返回true继续遍历
				// if (this.isNoEX) {
				// 	let a = []
				// 	item.order_goods.some(item1 => {
				// 		// 1130
				// 		if (item1.group_type == 0 || item1.group_type == 4 || item1.group_type == 5) {
				// 			if (!item1.time) {
				// 				console.log(item1);
				// 				// 1是快递 2是自提
				// 				if (item.self == 1) {
				// 					this.tui.toast(`请选择${item1.title}发货时间`)
				// 				} else {
				// 					this.tui.toast(`请选择${item1.title}自提时间`)
				// 				}
				// 				return true
				// 			} else if (!item1.department) {
				// 				this.tui.toast(`请选择${item1.title}生产部门`)
				// 				return true
				// 			} else {
				// 				a.push({
				// 					id: item1.id,
				// 					time: item1.time,
				// 					department: item1.department
				// 				})
				// 			}
				// 		} else {
				// 			let nowtimec = this.formDate(item1.date)
				// 			a.push({
				// 				id: item1.id,
				// 				time: nowtimec,
				// 				department: item1.department
				// 			})
				// 		}
				// 	})
				// 	if (a.length == item.order_goods.length) {
				// 		this.isNoEX = false
				// 		this.api.confirmOrder({
				// 				order: item.id,
				// 				list: JSON.stringify(a)
				// 			})
				// 			.then(res => {
				// 				if (res.data.code == 200) {
				// 					if (item.self == 1) {
				// 						this.curren = 2
				// 						this.isNoEX = true
				// 						this.orderListAll(3)
				// 					} else {
				// 						this.curren = 2
				// 						this.isNoEX = true
				// 						this.orderListAll(3)
				// 					}
				// 				} else {
				// 					this.tui.toast(res.data.msg)
				// 				}
				// 			})
				// 			.catch(err => {
				// 				this.tui.toast(err.data)
				// 				this.isNoEX = true
				// 			})
				// 	} else {

				// 	}
				// } else {
				// 	this.tui.toast('请勿重复提交')
				// }
			},
			// 关闭弹框
			close(e) {
				this.calendar = false

			},
			// picker
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.index = e.target.value
			},
			calendarChange(e) {
				console.log(e.fulldate)
				this.isShow = true

			},
			// 确认发货
			confirmDelivery(item) {

				if (item.status == 4) {
					uni.navigateTo({
						url: './confirmDelivery/deliveryAllOrPart/deliveryAllOrPart?status=' + item.status +
							'&id=' + item.id
					})
				}
				if (item.status == 5) {
					uni.navigateTo({
						url: './confirmDelivery/deliveryCourier/deliveryCourier?status=' + item.status + '&id=' +
							item.id
					})
				}
			},
			// 查看评价
			checkEvaluation(item) {
				console.log(12);
				uni.navigateTo({
					url: './historyEvaluation/historyEvaluation?order_id=' + item.id
				})
			},
			// 针对于退款 显示时间
			timeShow(time, spec, self, stock, amount, item1) {
				console.log(item1);
				// time后台配置的时间系数，spec规格,self判断是快递还是自提
				if (item1.group_type == 0) {
					let cn = spec.split(',')[0] //获取是什么类型
					if (cn == '种子') {
						// this.tiemCnv='预计一周内可发货/可自提'
						if (self == 0) {
							return '预计一周内可自提'
						} else {
							return '预计一周内可发货'
						}
					} else if (cn == '种苗') {
						if (self == 0) {
							return '预计' + (Number(time) + 7) + '天后可自提'
						} else {
							return '预计' + (Number(time) + 7) + '天后可发货'
						}
					} else if (cn == '种球') {
						if (self == 0) {
							return '待业务员确认订单后确认自提时间'
						} else {
							return '待业务员确认订单后确认发货时间'
						}
					}
				}
				if (item1.group_type != 0) {
					if (self == 0) {
						let c = this.formDate(item1.date)
						return '确定在' + c + '可自提'

					}
					if (self != 0) {
						let c = this.formDate(item1.date)
						return '确定在' + c + '可发货'
					}
				}
			},
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size;
				const $this = this
				this.api.orderListAll({
					dataType: 'all',
					pageIndex: pageNum,
					pageSize:pageSize,
					keywords:$this.searchMobile
				}).then(res => {
					const totalCount = res.data.data.orderList.total
					const orderLength = res.data.data.orderList.records.length
					console.log(res)
					let curPageLen = orderLength
					if (page.num == 1) this.datalist = [];
					const serverList = res.data.data.orderList.records
					const curPageData = []
					serverList.forEach(order => {
						const json = $this.toNewOrderJson(order)
						curPageData.push(json)
					})
					this.datalist = this.datalist.concat(curPageData);
					this.mescroll.endBySize(curPageLen, totalCount);

				}).catch(err => {
					this.tui.toast(err)
					this.mescroll.endSuccess()
				})
			},
			// 上拉加载

			// 是否是农资订单
			isFarmGoodOrder(orderInfo) {
				let goods = orderInfo.order_goods;
				if (!goods || goods.length === 0) {
					return false;
				}
				let arr = goods[0].spec.split(',');
				if (arr.length === 0) {
					return false;
				}
				return arr[0] === '农资';
			}
		},
	}
</script>
<style lang="less" scoped>
	page {
		background-color: #F9F9F9;
	}

	.content-pop {
		// position: relative;
		position: absolute;
		top: 39%;
		left: 0;
		width: 100%;
	}

	.top {
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #fff;
		position: absolute;
		top: -12%;
		left: 0;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		border-bottom: 1rpx solid #c8c7cc;
		font-size: 36rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;

		.confirm {
			color: #077840;
		}
	}

	.order-input {
		width: 100%;
		padding-top: 30rpx;
		padding-left: 25rpx;
		padding-right: 25rpx;
		box-sizing: border-box;
		background-color: #fff;
		position: fixed;
		top: 84rpx;
		left: 0;
		z-index: 123;


		input {
			height: 72rpx;
			width: 100%;
			background-color: #F6F6F6;
			border-radius: 36px;
			padding-left: 224rpx;
			box-sizing: border-box;
			margin-bottom: 30rpx;

			&:placeholder {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #BEBEBE;
				line-height: 72rpx;
				text-align: center;
			}

		}

		.search-icon {
			width: 29rpx;
			height: 31rpx;
			color: #BEBEBE;
			position: absolute;
			top: 52rpx;
			left: 210rpx;

			.uni-icons {
				font-size: 30rpx;
			}
		}

		.toptab {
			// height: 102rpx;
			// margin-left: 30rpx;
			overflow-x: scroll;
			white-space: nowrap;

			.item {
				height: 60rpx;
				font-size: 30rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				// line-height: 60rpx;
				display: inline-block;
				margin-left: 30rpx;
				margin-right: 30rpx;

				// margin-top: 20rpx;
				&:first-child {
					margin-left: 10rpx;
				}
			}

			.active {
				font-weight: 500;
				color: #077840 !important;
			}

			.bottom-line {
				width: 60rpx;
				height: 4rpx;
				background: #077840;
				margin: 0 auto;
				margin-top: 16rpx;
			}
		}
	}

	.sta {
		height: 52rpx;
		background: #F3F8F6;
		border-radius: 8rpx;
		font-size: 22rpx;
		line-height: 52rpx;
		text-align: center;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #077840;
		// margin-bottom: 30rpx;
		padding: 0 10rpx;
		box-sizing: border-box;
	}

	.goods-sta {
		display: inline-block;
	}

	.goods-sta1 {
		// width: 252rpx;
		display: inline-block;

	}

	.goods-sta2 {
		display: inline-block;
		color: #999999;
		background-color: #EEEEEE;
	}

	.item-content {
		background-color: #F9F9F9;
		padding-top: 130rpx;
		box-sizing: border-box;

		.item {
			width: 690rpx;
			// height: 600rpx;
			margin: 0 auto;
			margin-top: 20rpx;
			background-color: #fff;
			padding-bottom: 30rpx;
			box-sizing: border-box;


			&:last-child {
				margin-bottom: 20rpx;
			}
		}

		.buyers {
			.buyers-bigBox {
				margin: 0 30rpx;

				.buyers-box {
					width: 100%;
					height: 99rpx;
					line-height: 99rpx;
					border-bottom: 2px solid #EEEEEE;
					display: flex;
					justify-content: space-between;

					.buyers-left {
						display: flex;
						justify-content: flex-start;

						.courier {
							width: 108rpx;
							height: 52rpx;
							border-radius: 8px;
							border: 2px solid #077840;
							margin-top: 20rpx;
							font-size: 22rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #077840;
							line-height: 52rpx;
							text-align: center;
						}

						.buyers-name {
							font-size: 26rpx;
							font-family: PingFangSC-Medium, PingFang SC;
							font-weight: 500;
							color: #333333;
							margin-right: 20rpx;
						}
					}

					.buyers-right {
						.buyers-mobile {
							font-size: 26rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #077840;
							margin-right: 20rpx;
						}

						.goods-status {
							font-size: 26rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #077840;
						}
					}

				}

				.goods-detail {
					// height: 350rpx;
					width: 100%;
					border-bottom: 2px solid #EEEEEE;
					margin-top: 28rpx;

					.goods-newly {
						margin-bottom: 28rpx;
						display: flex;
						justify-content: space-between;

						&_icon {
							width: 100rpx;
							height: 50rpx;
							font-size: 24rpx;
							font-family: PingFangSC-Medium, PingFang SC;
							font-weight: 500;
							color: #FFFFFF;
							line-height: 50rpx;
							background: linear-gradient(54deg, #FF7436 0%, #FF3333 100%);
							border-radius: 16rpx 0px 16rpx 0px;
							text-align: center;
						}

						/* 秒杀颜色 */
						&_color {
							background: linear-gradient(270deg, #FF904C 0%, #FF5F43 47%, #FF4B90 100%);
						}
					}

					.goods-top {
						display: flex;
						justify-content: flex-start;

						.goods-img {
							width: 180rpx;
							height: 180rpx;
							margin-right: 20rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}

						.goods-detail-text {
							height: 180rpx;
							width: 430rpx;

							.goods {
								display: flex;
								justify-content: space-between;
								margin-bottom: 10rpx;
								font-size: 28rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #333333;
							}

							.goods-species {
								display: flex;
								justify-content: space-between;
								font-size: 24rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #999999;
							}
						}
					}

					.packing {
						display: flex;
						justify-content: space-between;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						margin: 20rpx 0;

						.packing_right {
							flex: 1;
							margin-left: 30rpx;
						}
					}

					.total-price {
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						margin-bottom: 30rpx;

						.total {
							color: #333333;
						}
					}
				}

				.order-number {
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					margin-top: 28rpx;

					.number {
						color: #333333;
					}
				}

				.order-time {
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					margin-top: 20rpx;
					margin-bottom: 30rpx;

					.time {
						color: #333333;
					}
				}

				.order-btn {
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					display: flex;
					justify-content: flex-end;

					.btn {
						width: 136rpx;
						height: 64rpx;
						line-height: 64rpx;
						text-align: center;
						background: #FFFFFF;
						border-radius: 8rpx;
					}

					.refund-btn {
						border: 2rpx solid #CECECE;
						// box-sizing: border-box;
						color: #666666;
					}

					.confirm-btn {
						border: 2rpx solid #077840;
						// box-sizing: border-box;
						color: #077840;
						margin-left: 10rpx;
					}

				}
			}
		}
	}

	.common {
		display: flex;
		justify-content: flex-end;
	}

	.sta-sty {
		view {
			margin-bottom: 0;
			margin: 4rpx 0 !important;
		}

		.sta1 {
			margin-right: 312rpx !important;
		}

		.sta2 {
			margin-right: 226rpx !important;
		}

		.sta3 {
			margin-right: 268rpx !important;
		}
	}

	/deep/uni-model .uni-model {
		width: 560rpx;
		height: 360rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
	}

	/deep/uni-modal .uni-modal__title {
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	/deep/uni-modal .uni-modal__bd {
		font-size: 30rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
	}

	.pop-up {
		width: 100%;
		height: 43%;
		background: rgba(0, 0, 0, .7);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9999;

		.calendar {
			width: 750rpx;
			height: 608rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 0px 0px;
			position: absolute;
			bottom: 0%;
			left: 0%;
			// padding: 0 10rpx;
			box-sizing: border-box;
		}
	}

	/deep/.w-picker-header uni-text:last-child {
		color: #077840 !important;
	}

	.time1 {
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FF6269;
		margin: 20rpx 0rpx;
	}

	.quanbu {
		width: 180rpx !important;
		background-color: #EEEEEE !important;
		color: #999999 !important;
		border: 0 !important;
	}

	.btns {
		border: 1px solid #097840;
		padding: 5px;
		border-radius: 5px;
		color: #097840;
	}
</style>